package com.stgl.action;

import com.stgl.service.JffsService;
import com.stgl.util.ExportExcel;
import net.sf.jxls.exception.ParsePropertyException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/jffs")
public class jffs {
    @Resource
    private JffsService jffsService;

    @RequestMapping("getJffs.html")
    @ResponseBody
    public Map<String,Object>getJffs(HttpServletRequest request, HttpServletResponse response){
        Map<String,Object>gmap=new HashMap<String,Object>();
        HttpSession session=((HttpServletRequest)request).getSession();
        if(session.getAttribute("csid")!=null){
            String csid=session.getAttribute("csid").toString();
            gmap.put("csid",csid);
        }
        List<Map<String,Object>>list1=jffsService.getJffs(gmap);
        if(list1.size()>0){
           return  list1.get(0);
        }
        return new HashMap<String,Object>();
    }



    @RequestMapping("getJffsBycsid.html")
    @ResponseBody
    public Map<String,Object>getJffsBycsid(HttpServletRequest request, HttpServletResponse response){
        String csid=request.getParameter("csid").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("csid",csid);
        List<Map<String,Object>>list1=jffsService.getJffs(gmap);
        if(list1.size()>0){
            return  list1.get(0);
        }
        return new HashMap<String,Object>();
    }


    @RequestMapping("updateJffs.html")
    @ResponseBody
    public Boolean updateJffs(HttpServletRequest request, HttpServletResponse response){
        String fs1=request.getParameter("fs1").trim();
        String fs2=request.getParameter("fs2").trim();
        String fs3=request.getParameter("fs3").trim();
        String fs1state=request.getParameter("fs1state").trim();
        String fs2state=request.getParameter("fs2state").trim();
        String fs3state=request.getParameter("fs3state").trim();

        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("fs1",fs1);
        gmap.put("fs2",fs2);
        gmap.put("fs3",fs3);
        gmap.put("fs1state",fs1state);
        gmap.put("fs2state",fs2state);
        gmap.put("fs3state",fs3state);

        HttpSession session=((HttpServletRequest)request).getSession();
        if(session.getAttribute("csid")!=null){
            String csid=session.getAttribute("csid").toString();
            gmap.put("csid",csid);
        }
        List<Map<String,Object>>list1=jffsService.getJffs(gmap);
        if(list1.size()>0){
            int i=jffsService.updateJffs(gmap);
            if(i>=0){
                return true;
            }
        }else{
            int i=jffsService.addJffs(gmap);
            if(i>=0){
                return true;
            }
        }
        return false;
    }


}
